using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using Utility;
using BUS;
public partial class Admin_TTGiaoDichList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    
    private void load_data()
    {
        PagerV2_8_1.PageSize = 5;
        Criteria cri = new Criteria();
        int Total = 0;
        if (txt_idgd.Text != "")
        {
            cri.add(Condition.AND, tbTTGiaoDichColumns.IdTTGiaoDich.ToString(), Condition.EQUAL, int.Parse(txt_idgd.Text));
        }
        //PagerV2_8_1 .PageSize =int.Parse (ConfigurationManager.AppSettings ["pagesize"].ToString ());
        tbTTGiaoDichCollection  ttgdcolection = tbTTGiaoDichBUS .Get(cri.Criter, PagerV2_8_1.CurrentIndex,
                                                           PagerV2_8_1.PageSize, tbTTGiaoDichColumns .IdHinhThuc .ToString(),
                                                           OrderDirection.ASC.ToString(), out Total);
        Repeater1.DataSource = ttgdcolection;
        Repeater1.DataBind();
        PagerV2_8_1.ItemCount = Total;
        if (Total <= PagerV2_8_1.PageSize)
            PagerV2_8_1.Visible = false;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            Literal lit_MaTT = (Literal)e.Item.FindControl("lit_MaTT");
            HyperLink hyp_MaDH = (HyperLink)e.Item.FindControl("hyp_MaDH");
            Literal lit_HinhThucTT = (Literal)e.Item.FindControl("lit_HinhThucTT");
            Literal lit_SoTien = (Literal)e.Item.FindControl("lit_SoTien");

            tbTTGiaoDich ttgiaodich = (tbTTGiaoDich)e.Item.DataItem;
            lit_MaTT.Text = ttgiaodich.IdTTGiaoDich.ToString() ;
            hyp_MaDH.Text = ttgiaodich.IdDH.ToString();
            int iD = int.Parse (ttgiaodich.IdHinhThuc.ToString());
            tbHinhThucTT htthanhtoan = tbHinhThucTTBUS.GetById(iD);
            hyp_MaDH.NavigateUrl = "DonHangList.aspx?id=" + ttgiaodich.IdDH.ToString();
            lit_HinhThucTT.Text = htthanhtoan.TenHinhThuc.ToString();
            lit_SoTien.Text = ttgiaodich.SoTien.ToString();
        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        load_data();
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        load_data();
    }
}
